<?php

namespace app\admin\model;

use app\common\model\douyinLogic;
use think\Model;


class DouyinAuth extends Model
{

    

    

    // 表名
    protected $name = 'douyin_auth';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'session_status_text'
    ];

    //事件
    protected static function init()
    {
        self::beforeInsert(function ($row) {
            $row->create_time = date("Y-m-d H:i:s");
        });
        self::beforeUpdate(function ($row) {
            $row->update_time = date("Y-m-d H:i:s");
        });
    }

    
    public function getSessionStatusList()
    {
        return ['0' => __('Session_status 0'), '1' => __('Session_status 1')];
    }


    public function getSessionStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['session_status']) ? $data['session_status'] : '');
        $list = $this->getSessionStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    //一对多 douyinShop
    public function douyinShop()
    {
        return $this->hasMany(douyinShop::class,'douyin_auth_id','id');
    }



}
